<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="pragma" content="no-cache" />
	<link rel="stylesheet" href="/css/style.css" type="text/css"/>
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/util.js"></script>
</head>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
////  email = "wenpin.qian@happyelements.com"                     ////
////  team = "Athene"                                             ////
////  warnings = "This is generated page,Do Not Modify!";         ////
////  tips = "Opera & IE not supported|Chrome & Safari sugguested"////
//////////////////////////////////////////////////////////////////////
window.returnValue=0;
var campaignId = null;
var getcampaignUrl = "/campaign/get/";
var editcampaignUrl = "/campaign/edit/";
var currentcampaign = null;
$(document).ready(function() {
	campaignId = window.dialogArguments;
	$.ajax({
		   type: "GET",
		   url: getcampaignUrl,
		   data: "campaignId=" + campaignId,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   var result = data.result;
				   $("#campaignId").val(result.campaignId);
				   $("#deployId").val(result.deployId);
				   $("#name").val(result.name);
				   $("#desc").val(result.desc);
				   $("#battlePointIds").val(result.battlePointIds);
				   $("#status").val(result.status);
				   $("#vip").val(result.vip);
				   $("#mapId").val(result.mapId);
				   $("#userLevel").val(result.userLevel);
				   $("#coorX").val(result.coorX);
				   $("#coorY").val(result.coorY);
				   $("#music").val(result.music);
				   $("#frontCompaignIds").val(result.frontCompaignIds);
				   $("#afterCompaignIds").val(result.afterCompaignIds);
				   				   
				   currentcampaign = result; 
				   listselectors();
				   window.returnValue=1;
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
});

function listselectors() {
var getMapSelectorUrl = "/special/Map/getList/";
$.ajax({
		   type: "GET",
		   url: getMapSelectorUrl,
		   data: "",
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   selectmapId(s2json(data.result));
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

function editcampaign() {
	var campaignIdParam = "campaignId=" + campaignId;
	var nameValue = $("#name").val();
	if(!checkString("名字",nameValue,false)) {
		return;
	}
	var nameParam = "name=" + xparseString(nameValue);
		
	var descValue = $("#desc").val();
	if(!checkString("描述",descValue,false)) {
		return;
	}
	var descParam = "desc=" + xparseString(descValue);
		
	var battlePointIdsValue = $("#battlePointIds").val();
	
	var battlePointIdsParam = "battlePointIds=" + battlePointIdsValue;
		
	var statusValue = $("#status").val();
	
	var statusParam = "status=" + statusValue;
		
	var vipValue = $("#vip").val();
	
	var vipParam = "vip=" + vipValue;
		
	var mapIdValue = $("#mapId").val();
	
	var mapIdParam = "mapId=" + mapIdValue;
		
	var userLevelValue = $("#userLevel").val();
	if(!checkInteger("用户等级",userLevelValue,false)) {
		return;
	}
	var userLevelParam = "userLevel=" + xparseInt(userLevelValue);
		
	var coorXValue = $("#coorX").val();
	if(!checkInteger("X坐标",coorXValue,false)) {
		return;
	}
	var coorXParam = "coorX=" + xparseInt(coorXValue);
		
	var coorYValue = $("#coorY").val();
	if(!checkInteger("Y坐标",coorYValue,false)) {
		return;
	}
	var coorYParam = "coorY=" + xparseInt(coorYValue);
		
	var musicValue = $("#music").val();
	
	var musicParam = "music=" + musicValue;
		
	var frontCompaignIdsValue = $("#frontCompaignIds").val();
	
	var frontCompaignIdsParam = "frontCompaignIds=" + frontCompaignIdsValue;
		
	var afterCompaignIdsValue = $("#afterCompaignIds").val();
	
	var afterCompaignIdsParam = "afterCompaignIds=" + afterCompaignIdsValue;
			
	$.ajax({
		   type: "POST",
		   url: editcampaignUrl,
		   		   data:  campaignIdParam + '&' +  nameParam  +'&'+   descParam  +'&'+   battlePointIdsParam  +'&'+   statusParam  +'&'+   vipParam  +'&'+   mapIdParam  +'&'+   userLevelParam  +'&'+   coorXParam  +'&'+   coorYParam  +'&'+   musicParam  +'&'+   frontCompaignIdsParam  +'&'+   afterCompaignIdsParam  ,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
			   	   beforeWindowClose();
				   window.close();
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

	
	
			function addbattlePointIds() {
			var battlePointIdsstr = $("#battlePointIds").val();
			var returnCallback = function(retvalue) {
				$('#battlePointIds').val(retvalue);
			}
			openDialog("/pages/core/SimpleArray.html",[1,battlePointIdsstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
	
	
			function selectmapId(options) {
			var optionHTML = "";
			for(var i in options) {
				optionHTML = optionHTML + "<option value='"+ options[i][0] +"'>" + options[i][1] + "</option>\n";
			}
			$("#mapId").html(optionHTML);
			if(currentcampaign != undefined) {
				$("#mapId").val(currentcampaign.mapId);
			}
		}
	
	
	
	
	
			function addfrontCompaignIds() {
			var frontCompaignIdsstr = $("#frontCompaignIds").val();
			var returnCallback = function(retvalue) {
				$('#frontCompaignIds').val(retvalue);
			}
			openDialog("/pages/core/SelectorArray.html",["Campaign","Campaign",frontCompaignIdsstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
			function addafterCompaignIds() {
			var afterCompaignIdsstr = $("#afterCompaignIds").val();
			var returnCallback = function(retvalue) {
				$('#afterCompaignIds').val(retvalue);
			}
			openDialog("/pages/core/SelectorArray.html",["Campaign","Campaign",afterCompaignIdsstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
		}
	
function openResource(fieldname,dependfield) {
	var param = "";
	if(dependfield!="") {
		param = $("#" + dependfield).val()
		if(param == null || param == "") {
			alert("你先把【" + $("#lbl_" + dependfield).html() + "】填了再上传");
			return;
		}
	}
	resourceDialog("campaign",$("#" + fieldname).val(),param,function(result) {
		if(result != undefined && result != "") {
			$("#" + fieldname).val(result);
		}
	});
}

function beforeWindowClose() {
	if(window.returnCallback) {
		window.returnCallback(window.returnValue);
	}
	window.onbeforeunload = null;
	return true;
}

</script>
<body onunload="beforeWindowClose()">
	<div class="addarea">
	<form action="/campaign/add" method="post">
		<table>
			<tbody>
				<tr>
					<td>ID</td><td><input type="text" id="campaignId" name="campaignId" disabled/></td>
					<td>发布Id</td><td><input type="text" id="deployId" name="deployId" disabled/></td>
				</tr>
			</tbody>
		</table>
		<table>
			<tbody>				
					<tr>					<td>
						<label for="name" id="lbl_name">名字</label>
													<input type="text" id="name" name="name" /><span class="tips">[文字]</span>
											</td>
									
										<td>
						<label for="desc" id="lbl_desc">描述</label>
													<input type="text" id="desc" name="desc" /><span class="tips">[文字]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="battlePointIds" id="lbl_battlePointIds">战点列表</label>
													<input type="text" id="battlePointIds" name="battlePointIds" value="[]" disabled/>
							<input type="button" value="..." onclick="addbattlePointIds()"/>
											</td>
									
										<td>
						<label for="status" id="lbl_status">状态</label>
																				<select id="status" name="status">
								
									<option value="-1">无</option>
								
									<option value="0">已开启</option>
								
									<option value="1">未开启</option>
								
									<option value="2">不显示</option>
								
									<option value="3">已通过</option>
															</select>
											</td>
					</tr>				
					<tr>					<td>
						<label for="vip" id="lbl_vip">VIP</label>
																				<select id="vip" name="vip">
								
									<option value="0">否</option>
								
									<option value="1">是</option>
															</select>
											</td>
									
										<td>
						<label for="mapId" id="lbl_mapId">地图ID</label>
													<select id="mapId" name="mapId">
							</select>
											</td>
					</tr>				
					<tr>					<td>
						<label for="userLevel" id="lbl_userLevel">用户等级</label>
													<input type="text" id="userLevel" name="userLevel" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="coorX" id="lbl_coorX">X坐标</label>
													<input type="text" id="coorX" name="coorX" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="coorY" id="lbl_coorY">Y坐标</label>
													<input type="text" id="coorY" name="coorY" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="music" id="lbl_music">音乐</label>
													<input type="text" id="music" name="music" disabled/>
							<input type="button" value="..." onclick="openResource('music','')"/><span class="tips">[资源]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="frontCompaignIds" id="lbl_frontCompaignIds">前置战役</label>
													<input type="text" id="frontCompaignIds" name="frontCompaignIds" value="[]" disabled/>
							<input type="button" value="..." onclick="addfrontCompaignIds()"/>
											</td>
									
										<td>
						<label for="afterCompaignIds" id="lbl_afterCompaignIds">后置战役</label>
													<input type="text" id="afterCompaignIds" name="afterCompaignIds" value="[]" disabled/>
							<input type="button" value="..." onclick="addafterCompaignIds()"/>
											</td>
					</tr>							</tbody>
		</table>
		<input type="button" onclick="editcampaign()" value="修改"/>
	</form>
	</div>
</body>